package oop;


//import com.toedter.calendar.JDateChooser;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.*;

public class Product extends JPanel{
        /**
       *
       */
      private static final long serialVersionUID = 1L;
   
 
      private JLabel labelMainHeader,labelSubHeader,labelProductCode,labelProductType,labelBrand,labelModel,labelProductPrice,labelPriceTotal,labelCurrency,labelUnit,labelPic;
      private JTextField txtProductCode,txtProductType,txtBrand,txtModel,txtProductPrice,txtPriceTotal;
      private JButton buttonFind,buttonSave,buttonDel,buttonBrowse;
      private JPanel p1;
      private JPanel p2;
      String picAddress = "",b = "";
   
      public Product(){
    	  setLayout(null);
    	  //setBackground(Color.WHITE);
    	  setComponent();
    	  setBounds(10,150, 569, 444);
      }

public void setComponent(){
       
	    p1 = new JPanel();
	    p1.setBorder(BorderFactory.createTitledBorder(null, "Products",TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION,new Font("Tahoma",Font.PLAIN,14)));
	    p1. setLayout(null);
	    add(p1);
	    p1.setBounds(1,10,567,190);
	    p1.setVisible(true);
	   
	   
	    p2 = new JPanel();
	    p2.setBorder(BorderFactory.createTitledBorder(null, "รูปสินค้า",TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION,new Font("Tahoma",Font.PLAIN,11)));
	    p2. setLayout(null);
	    add(p2);
	    p2.setBounds(1,210,567,235);
	    p2.setVisible(true);
        // set Font
        Font txtFont = new Font("Tahoma",Font.PLAIN,12);
       
        // set Button
        buttonFind = new JButton("ค้นหา");      buttonFind.setFont(txtFont);
        buttonFind.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        buttonFind.setIcon(new ImageIcon("D:\\Project\\src\\pic\\search.png"));
       
        buttonSave = new JButton("บันทึก");     buttonSave.setFont(txtFont);
        buttonSave.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        buttonSave.setIcon(new ImageIcon("D:\\Project\\src\\pic\\save.png"));
       
        buttonDel = new JButton("ลบ");          buttonDel.setFont(txtFont);
        buttonDel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        buttonDel.setIcon(new ImageIcon("D:\\Project\\src\\pic\\delete.png"));
       
        buttonBrowse = new JButton("เลือกรูป..");         buttonBrowse.setFont(txtFont);
        buttonBrowse.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
       
        // set Label
        labelMainHeader = new JLabel("PRODUCTS");                       labelMainHeader.setFont(new Font("Segoe UI",Font.BOLD,18));
        labelSubHeader = new JLabel("แสดงรายละเอียดและแก้ไขข้อมูลสินค้า..");    labelSubHeader.setFont(new Font("Tahoma",Font.PLAIN,11));
        labelProductCode = new JLabel("รหัสสินค้า:");                   labelProductCode.setFont(txtFont);
        labelProductType = new JLabel("ประเภทสินค้า:");                 labelProductType.setFont(txtFont);
        labelBrand = new JLabel("ยี่ห้อ:");                                             labelBrand.setFont(txtFont);
        labelModel = new JLabel("รุ่น:");                                               labelModel.setFont(txtFont);
        labelProductPrice = new JLabel("ราคา:");                                labelProductPrice.setFont(txtFont);
        labelPriceTotal = new JLabel("คงเหลือ:");                    labelPriceTotal.setFont(txtFont);
        labelUnit = new JLabel("ชิ้น");                                         labelUnit.setFont(txtFont);
        labelCurrency = new JLabel("บาท");                                      labelCurrency.setFont(txtFont);
        labelPic = new JLabel();
        labelPic.setHorizontalAlignment(JLabel.CENTER);
       
        //set TextField
        txtProductCode = new JTextField();                                      txtProductCode.setFont(txtFont);
        txtProductType = new JTextField();                                      txtProductType.setFont(txtFont);
        txtProductPrice = new JTextField();                                     txtProductPrice.setFont(txtFont);                              
        txtModel = new JTextField();                                            txtModel.setFont(txtFont);
        txtBrand = new JTextField();                                            txtBrand.setFont(txtFont);
        txtPriceTotal = new JTextField();                                       txtPriceTotal.setFont(txtFont);
       
        //add label to panel
        p1.add(labelMainHeader);
        p1.add(labelSubHeader);
        p1.add(labelProductCode);
        p1.add(labelProductType);
        p1.add(labelProductPrice);
        p1.add(labelBrand);
        p1.add(labelModel);
        p1.add(labelPriceTotal);
        p1.add(labelUnit);
        p1.add(labelCurrency);
       
        //add txtField
        p1.add(txtProductCode);
        p1.add(txtProductType);
        p1.add(txtBrand);
        p1.add(txtModel);
        p1.add(txtProductPrice);
        p1.add(txtPriceTotal);
       
        //add button
        p1.add(buttonFind);
        p1.add(buttonSave);
        p1.add(buttonDel);
        p1.add(buttonBrowse);
       
        p2.add(labelPic);
       
        // set position label
        labelMainHeader.setBounds(15, 20, 100, 20);
        labelSubHeader.setBounds(15, 47, 200, 15);
        labelProductCode.setBounds(30, 80, 80, 15);
        labelProductType.setBounds(13, 110, 80, 15);
        labelProductPrice.setBounds(55, 140, 80, 15);
        labelBrand.setBounds(265, 80, 80, 15);
        labelModel.setBounds(275, 110, 80, 15);
        labelCurrency.setBounds(215, 140, 80, 15);
        labelPriceTotal.setBounds(250, 140, 80, 15);
        labelUnit.setBounds(430, 140, 80, 15);
        labelPic.setBounds(5, 20, 545, 200);
       
        //set position txtField
        txtProductCode.setBounds(85, 80, 129, 22);
        txtProductType.setBounds(85, 110, 129, 22);
        txtProductPrice.setBounds(85, 140, 129, 22);
        txtBrand.setBounds(295, 80, 129, 22);
        txtModel.setBounds(295, 110, 129, 22);
        txtPriceTotal.setBounds(295, 140, 129, 22);
       
        //set position button
        buttonFind.setBounds(455, 50, 85, 23);
        buttonSave.setBounds(455, 80, 85, 23);
        buttonDel.setBounds(455, 110, 85, 23);
        buttonBrowse.setBounds(455, 140, 85, 23);
       
       
        buttonBrowse.addActionListener(new ActionListener() {
        	 
                      @Override
                      public void actionPerformed(ActionEvent arg0) {
                              // TODO Auto-generated method stub
                              FileDialog f = new FileDialog(new Frame());
                              f.setVisible(true);
                              
                              // if not select picture at first.It will not show.
                              if(f.getDirectory() == null){
                            	  if(b.equals(""))
                            		  labelPic.setIcon(new ImageIcon(b));
                              }
                              else{
                            	  String pic = f.getDirectory()+f.getFile();
                            	  picAddress = pic.replace("\\",    "\\\\");
                            	  b = picAddress;
                            	  labelPic.setIcon(new ImageIcon(picAddress));
                              }
                              
                      }
              });
             
              buttonFind.addActionListener(new ActionListener() {
                     
                      @Override
                      public void actionPerformed(ActionEvent arg0) {
                              // TODO Auto-generated method stub
                              ProductFind ProFind = new ProductFind();
                              ProFind.setVisible(true);
                      }
              });
      }
}


